home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Science / µSim 1.0b5 folder / source / Registers.c < prev    next >
Encoding:
Text File  |  1994-10-01  |  4.2 KB  |  174 lines  |  [TEXT/MMCC]

  1. /*
  2. Copyright © 1993,1994 by Fabrizio Oddone
  3. ••• ••• ••• ••• ••• ••• ••• ••• ••• •••
  4. This source code is distributed as freeware: you can copy, exchange, modify this
  5. code as you wish. You may include this code in any kind of application: freeware,
  6. shareware, or commercial, provided that full credits are given.
  7. You may not sell or distribute this code for profit.
  8. */
  9.  
  10. //#pragma load "MacDump"
  11.  
  12. #include    "UtilsSys7.h"
  13. #include    "Disasm.h"
  14. #include    "DoEditDialog.h"
  15. #include    "Globals.h"
  16. #include    "Main.h"
  17. #include    "Registers.h"
  18. #include    "SimUtils.h"
  19. #include    "Independents.h"
  20.  
  21. #if defined(FabSystem7orlater)
  22.  
  23. //#pragma segment Main
  24.  
  25. /* CLRRECT: makes a Rect an empty Rect */
  26. #define    CLRRECT(r)    (*(long *)&r = 0, *(long *)((Ptr)&r + 2) = 0)
  27.  
  28. ControlHandle    Ctrl_Base;
  29. short    regLineHeight;
  30. short    regDistFromTop;
  31. short    regVertSepLine;
  32. short    oldChoice;
  33.  
  34. static void Do_A_Button(ControlHandle theControl);
  35.  
  36.  
  37. void Update_Registers(WindowPtr w)
  38. {
  39. Str255    sTemp;
  40. register Handle    tempH;
  41. register short i,j;
  42.  
  43. EraseRect(&w->portRect);
  44. HLock(tempH = Get1Resource('STR#', kREG_NAMES));
  45. for(i = 0, j = regDistFromTop; i <= kDISP_REGS - 1; i++, j += regLineHeight) {
  46.     MoveTo(REG_LEFT + kDIST_FROMLEFT, j);
  47.     DrawString((ConstStr255Param)GetPtrIndHString(tempH, i));
  48.     MoveTo(REG_LEFT + regVertSepLine + kDIST_FROMVERTSEP + 1, j);
  49.     FromNumToString(sTemp, gRegs[i], oldChoice);
  50.     DrawString(sTemp);
  51.     }
  52. HUnlock(tempH);
  53. /*  Draw the horizontal line  */
  54. MoveTo(REG_LEFT, kREG_HORZSEPLINE);
  55. LineTo(REG_RIGHT, kREG_HORZSEPLINE);
  56. /*  Draw the vertical line  */
  57. MoveTo(regVertSepLine, REG_TOP);
  58. LineTo(regVertSepLine, REG_BOTTOM - 1);
  59. UpdtControl(w, w->visRgn);
  60. }
  61.  
  62. void Do_Registers(WindowPtr w, EventRecord *theEvent)
  63. {
  64. Rect    tempRect, oldRect, shiftingRect;
  65. Point    myPt;
  66. ControlHandle    theControl;
  67. register short    code;
  68. register Boolean    inbigrect;
  69.  
  70. myPt = theEvent->where;
  71. GlobalToLocal(&myPt);
  72. if (FindControl(myPt, w, &theControl) != 0) {
  73.     if (TrackControl(theControl, myPt, (ControlActionUPP)-1L) == inLabel)
  74.         if ((code = GetCtlValue(Ctrl_Base)) != oldChoice) {
  75.             oldChoice = code;
  76.             tempRect.top = REG_TOP;
  77.             tempRect.left = REG_LEFT + regVertSepLine + 1;
  78.             tempRect.bottom = REG_BOTTOM;
  79.             tempRect.right = REG_RIGHT;
  80.             InvalRect(&tempRect);
  81.             }
  82.     }
  83. else {
  84.     tempRect.top = REG_TOP;
  85.     tempRect.left = REG_LEFT;
  86.     tempRect.bottom = REG_BOTTOM;
  87.     tempRect.right = REG_RIGHT;
  88.     if (PtInRect(myPt, &tempRect)){
  89.         CLRRECT(oldRect);
  90.         do {
  91.             GetMouse(&myPt);
  92.             if (!PtInRect(myPt, &oldRect)) {
  93.                 if (inbigrect = PtInRect(myPt, &tempRect)) {
  94.                     shiftingRect.top = REG_TOP;
  95.                     shiftingRect.left = REG_LEFT;
  96.                     shiftingRect.bottom = REG_TOP + regLineHeight;
  97.                     shiftingRect.right = REG_RIGHT;
  98.                     for(code = kREG_PC;
  99.                         !(PtInRect(myPt, &shiftingRect)&&(code <= kREG_LOW8));
  100.                         code++, shiftingRect.top += regLineHeight,
  101.                         shiftingRect.bottom += regLineHeight)
  102.                             ;
  103.                     InvertRect(&oldRect);
  104.                     InvertRect(&shiftingRect);
  105.                     oldRect = shiftingRect;
  106.                     }
  107.                 else {
  108.                     InvertRect(&oldRect);
  109.                     CLRRECT(oldRect);
  110.                     }
  111.                 }
  112.             }
  113.         while( StillDown() );
  114.         if (inbigrect) {
  115.             InvertRect(&oldRect);
  116.             if(DoEditDialog(code, kREG_EXTNAMES, oldChoice)) {
  117.                 oldRect.left += regVertSepLine+1;
  118.                 InvalRect(&oldRect);
  119.                 if (code == kREG_PC)
  120.                     InvalDisasm();
  121.                 }
  122.             UnloadSeg(DoEditDialog);
  123.             }
  124.         }
  125.     }
  126. }
  127.  
  128. /* ChangedRegister: to tell us that a register has changed its value */
  129.  
  130. void ChangedRegister(short whichreg)
  131. {
  132. Rect    tempRect;
  133. GrafPtr    savePort;
  134.  
  135. GetPort(&savePort);
  136. SetPort(gWPtr_Registers);
  137. tempRect.top = REG_TOP + (regLineHeight * whichreg);
  138. tempRect.left = REG_LEFT + regVertSepLine+1;
  139. tempRect.bottom = tempRect.top + regLineHeight;
  140. tempRect.right = REG_RIGHT;
  141. InvalRect(&tempRect);
  142. if (whichreg == kREG_PC)
  143.     InvalDisasm();
  144. SetPort(savePort);
  145. }
  146.  
  147. /* ChangedAllRegisters: to tell us that _all_ registers have changed */
  148.  
  149. void ChangedAllRegisters(void)
  150. {
  151. Rect    tempRect;
  152. GrafPtr    savePort;
  153.  
  154. GetPort(&savePort);
  155. SetPort(gWPtr_Registers);
  156. tempRect.top = REG_TOP;
  157. tempRect.left = REG_LEFT + regVertSepLine+1;
  158. tempRect.bottom = tempRect.top + (regLineHeight * kREG_ZERO);
  159. tempRect.right = REG_RIGHT;
  160. InvalRect(&tempRect);
  161. InvalDisasm();
  162. SetPort(savePort);
  163. }
  164.  
  165. /* procedure called when closing the Registers window */
  166.  
  167. void CloseRegisters(WindowPtr w)
  168. {
  169. DoCloseWindow(w, kMItem_Registers);
  170. }
  171.  
  172. #endif
  173.  
  174.